﻿using PLCS.Application.Contracts.SolutionApp.Dtos;
using System.Threading.Tasks;

namespace PLCS.App.ProcessSolution.ViewModels.Solution;

public class SolutionViewModel : NavigationPagedCurdViewModel<SolutionDto, SolutionEditDto, ISolutionService>
{
    private string _solutionNo;

    public string SolutionNo
    {
        get { return _solutionNo; }
        set { SetProperty(ref _solutionNo, value); }
    }

    public SolutionViewModel(ISolutionService service) : base(service)
    {
    }

    public override async Task GetPageData(int pageIndex)
    {
        try
        {
            UpdateLoading(true);
            var res = await _service.GetListBySearchAsync((pageIndex - 1) * PageSize, PageSize, SolutionNo);
            TotalCount = (int)res.TotalCount;
            SetPageCount();
            DataGridList = res.Items.ToObservable();
        }
        finally
        {
            UpdateLoading(false);
        }
    }
}